package org.lanqiao.practice_3;

import org.junit.Test;

public class TestDriver1 {
	// 字符创排序
	@Test
	public void test() {
		String[] str = { "dad", "bood", "bada", "Admin", "  ", "Good", "aete", "cc", "Ko", "Beta", "Could" };
		for (int i = str.length; i>0; i--) {
			for (int j = 1; j <i; j++) {
				if (comperaString(str[j - 1], str[j]) > 0) {
					String temp = str[j - 1];
					str[j - 1] = str[j];
					str[j] = temp;

				}
			}
		}
		for (String string : str) {
			System.out.print(string + "  ");
		}
	}
	//@Test
	public int comperaString(String str1, String str2) {
		// String str1, String str2
		// String str1="Beta";
		// String str2="bada";
		int str1Len = str1.length();
		int str2Len = str2.length();
		int result = str1Len - str2Len;
		// 求出字符串最小的长度
		int min = Math.min(str1Len, str2Len);
		char[] ch1 = str1.toCharArray();
		char[] ch2 = str2.toCharArray();
		for (int i = 0; i < min; i++) {
			if (ch1[i] != ch2[i]) {
				int c1 = ch1[i] >= 'a' ? ch1[i] - 96 : ch1[i] - 64;
				int c2 = ch2[i] >= 'a' ? ch2[i] - 96 : ch2[i] - 64;
				if (c1 != c2) {
					result = c1 - c2;
					break;
				} else {
					result = ch1[i] - ch2[i];
					break;
				}
			}
		}
		 return result;
		//System.out.println(result);
	}

}
